package tmall.action;

import java.lang.reflect.Method;
import org.apache.commons.lang3.text.WordUtils;
import org.springframework.beans.factory.annotation.Autowired;

import tmall.service.CategoryService;
import tmall.service.OrderItemService;
import tmall.service.OrderService;
import tmall.service.ProductImageService;
import tmall.service.ProductService;
import tmall.service.PropertyService;
import tmall.service.PropertyValueService;
import tmall.service.ReviewService;
import tmall.service.UserService;

public class Action4Service extends Action4Pojo{
	@Autowired
	CategoryService categoryService;
	
	@Autowired
	PropertyService propertyService;
	
	@Autowired
	ProductService productService;
	
	@Autowired
	ProductImageService productImageService;
	
	@Autowired
	PropertyValueService propertyValueService;
	
	@Autowired
	UserService userService;
	
	@Autowired
	OrderService orderService;
	
	@Autowired
	OrderItemService orderItemService;
	
	@Autowired
	ReviewService reviewService;
	
	 public void t2p(Object o){
         try {
             Class clazz = o.getClass();
             int id = (Integer) clazz.getMethod("getId").invoke(o);
             Object persistentBean = categoryService.get(clazz, id);

             String beanName = clazz.getSimpleName();
             Method setMethod = getClass().getMethod("set" + WordUtils.capitalize(beanName), clazz);
             setMethod.invoke(this, persistentBean);
         } catch (Exception e) {
             // TODO Auto-generated catch block
             e.printStackTrace();
         }
	 }
}
